package com.sketch.commom.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Value("${spring.profiles.active:dev}")
    private String activeProfile;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                //非生产环境打开配置
                .enable(!activeProfile.equals("prod"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sketch.controller")) // 指定要扫描的控制器包路径
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("sketch API") // 设置 API 标题
                .description("APIs for managing sketch") // 设置 API 描述
                .version("1.0.0") // 设置 API 版本
                .build();
    }
}